This program calculates probabilities for observing an event at least once, given the true probability inputs. Creates a table that can display multiple probabilities.
The program is written in R.
View Code
function(event_rates, sample_size)
{
event_probabilities = data.frame(n = numeric(),
rate = numeric(),
probability = character())
for (event_rate in unique(event_rates)) {
event_probability = paste0(round((1 - ((1 - event_rate)^sample_size)) * 100, 1), "%")
event_probabilities = rbind(event_probabilities,
data.frame(n = sample_size,
rate = event_rate,
probability = event_probability))
}
result = list(event_probabilities = event_probabilities)
return(jsonlite::toJSON(result, pretty = TRUE))
}